﻿
$.CheckdFormat = function (v, r, i) {
    if (v == true || v == "true" || v > 0) {
        return "<span style='color:green;font-weight:bold'><i class='fa fa-check'></i></span>";
    } else {
        return "";
    }
}

$.FailedFormat = function(v, r, i) {
    if (v == false) {
        return "<span style='color:red;font-weight:bold'>×</span>";
    } else {
        return "";
    }
}

$.ImageFormat = function (v, r, i, style) {
    if (!$.IsNullOrEmpty(v)) {
        return "<img src='" + v + "' style='" + style + "'/>";
    } else {
        return "<div style='" + style + "'><i class='fa fa-user-circle-o'></i></div>";
    }
}

$.PercentFmt = function (v) {
    if (v) { return (v * 100) + '%'; }
}

$.PriceFmt = function (v) {
    if (v) { return '￥' + v; }
    return v;
}

$.DateFmt = function (value, row, index) {
    if (value) {
        var d = $.StringToDate(value);
        if (d instanceof Date) {
            var s = d.getFullYear();
            var m = d.getMonth() + 1;
            s += (m >= 10 ? ("-" + m) : ("-0" + m));
            var dd = d.getDate();
            s += (dd >= 10 ? ("-" + dd) : ("-0" + dd));
            return s;
        }
        return value;
    }
}

$.DateTimeFmt = function (value, row, index) {
    if (value) {
        var d = $.StringToDate(value);
        if (d instanceof Date) {
            var s = d.getFullYear();
            var m = d.getMonth() + 1;
            s += (m >= 10 ? ("-" + m) : ("-0" + m));
            var dd = d.getDate();
            s += (dd >= 10 ? ("-" + dd) : ("-0" + dd));

            var h = d.getHours();
            s += (h >= 10 ? (" " + h) : (" 0" + h));
            var mm = d.getMinutes();
            s += (mm >= 10 ? (":" + mm) : (":0" + mm));
            var ss = d.getSeconds();
            s += (ss >= 10 ? (":" + ss) : (":0" + ss));

            return s;
        }
        return value;
    }
}

$.FileTypeFmt = function (v) {
    var type = "file-small";
    switch (v) {
        case 0: type = "excel-small"; break;
        case 1: type = "word-small"; break;
        case 2: type = "ppt-small"; break;
        case 3: type = "z7-small"; break;
        case 4: type = "rar-small"; break;
        case 5: type = "zip-small"; break;
        case 6: type = "iso-small"; break;
        case 7: type = "msg-small"; break;
        case 8: type = "html-small"; break;
        case 9: type = "sys-small"; break;
        case 10: type = "ini-small"; break;
        case 11: type = "help-small"; break;
        case 12: type = "exe-small"; break;
        case 13: type = "dll-small"; break;
        case 14: type = "ttf-small"; break;
        case 15: type = "pdf-small"; break;
        case 16: type = "ps-small"; break;
        case 17: type = "ai-small"; break;
        case 18: type = "fi-small"; break;
        case 19: type = "swf-small"; break;
        case 20: type = "txt-small"; break;
        case 21: type = "rtf-small"; break;
        case 22: type = "reg-small"; break;
        case 23: type = "rmvb-small"; break;
        case 24: type = "avi-small"; break;
        case 25: type = "q-small"; break;
        case 26: type = "mq-small"; break;
        case 27: type = "wav-small"; break;
        case 28: type = "jpeg-small"; break;
        case 29: type = "gif-small"; break;
        case 30: type = "png-small"; break;
        case 31: type = "bmp-small"; break;
        case 32: type = "tiff-small"; break;
        case 33: type = "emf-small"; break;
        case 34: type = "wmf-small"; break;
        case 35: type = "ico-small"; break;
        case 36: type = "raw-small"; break;
        case 37: type = "pp-small"; break;
        case 38: type = "config-small"; break;
        case 39: type = "bt-small"; break;
        case 40: type = "folder-small"; break;
        case 41: type = "msi-small"; break;
        case 42: type = "pdm-small"; break;
        case 43: type = "database-small"; break;
        case 44: type = "cs-small"; break;
    }

    return "<i class='file-small-icon " + type + "'></i>";
}

$.FileTypeFmt = function (v) {
    var type = "file-small";
    switch (v) {
        case 0: type = "excel-small"; break;
        case 1: type = "word-small"; break;
        case 2: type = "ppt-small"; break;
        case 3: type = "z7-small"; break;
        case 4: type = "rar-small"; break;
        case 5: type = "zip-small"; break;
        case 6: type = "iso-small"; break;
        case 7: type = "msg-small"; break;
        case 8: type = "html-small"; break;
        case 9: type = "sys-small"; break;
        case 10: type = "ini-small"; break;
        case 11: type = "help-small"; break;
        case 12: type = "exe-small"; break;
        case 13: type = "dll-small"; break;
        case 14: type = "ttf-small"; break;
        case 15: type = "pdf-small"; break;
        case 16: type = "ps-small"; break;
        case 17: type = "ai-small"; break;
        case 18: type = "fi-small"; break;
        case 19: type = "swf-small"; break;
        case 20: type = "txt-small"; break;
        case 21: type = "rtf-small"; break;
        case 22: type = "reg-small"; break;
        case 23: type = "rmvb-small"; break;
        case 24: type = "avi-small"; break;
        case 25: type = "q-small"; break;
        case 26: type = "mq-small"; break;
        case 27: type = "wav-small"; break;
        case 28: type = "jpeg-small"; break;
        case 29: type = "gif-small"; break;
        case 30: type = "png-small"; break;
        case 31: type = "bmp-small"; break;
        case 32: type = "tiff-small"; break;
        case 33: type = "emf-small"; break;
        case 34: type = "wmf-small"; break;
        case 35: type = "ico-small"; break;
        case 36: type = "raw-small"; break;
        case 37: type = "pp-small"; break;
        case 38: type = "config-small"; break;
        case 39: type = "bt-small"; break;
        case 40: type = "folder-small"; break;
        case 41: type = "msi-small"; break;
        case 42: type = "pdm-small"; break;
        case 43: type = "database-small"; break;
        case 44: type = "cs-small"; break;
    }

    return "<i class='file-small-icon " + type + "'></i>";
}

$.GetFileType = function (v, sb) {
    if (sb == undefined) { sb = "small"; }
    var type = "file";
    v = v.toLowerCase();
    switch (v) {
        case ".xls":
        case ".xlsx":
            type = "excel"; break;
        case ".doc":
        case ".docx":
            type = "word"; break;
        case ".ppt":
        case ".pptx":
            type = "ppt"; break;
        case ".z7":
            type = "z7"; break;
        case ".rar":
            type = "rar"; break;
        case ".zip":
            type = "zip"; break;
        case ".iso":
            type = "iso"; break;
        case ".msg":
            type = "msg"; break;
        case ".htm":
        case ".html":
            type = "html"; break;
        case ".sys":
            type = "sys"; break;
        case ".ini":
            type = "ini"; break;
        case ".exe":
            type = "exe"; break;
        case "dll":
            type = "dll"; break;
        case ".pdf":
            type = "pdf"; break;
        case ".txt":
            type = "txt"; break;
        case ".rm":
        case ".rmvb":
            type = "rmvb"; break;
        case ".avi":
            type = "avi"; break;
        case ".jpg":
        case ".jpeg":
            type = "jpeg"; break;
        case ".gif":
            type = "gif"; break;
        case "png":
            type = "png"; break;
        case "bmp":
            type = "bmp"; break;
        case ".config":
            type = "config"; break;
        case "msi":
            type = "msi"; break;
        case ".cs":
            type = "cs"; break;
    }

    return type + "-" + sb;
}

$.FileSizeFmt = function (v) {
    if (v > 0) {
        if (v < 1024) {
            return v + 'B';
        } else if (v < 1024 * 1024) {
            return (v / 1024).toFixed(2) + 'KB';
        } else if (v < 1024 * 1024 * 1024) {
            return (v / 1024 / 1024).toFixed(2) + 'MB';
        } else if (v < 1024 * 1024 * 1024 * 1024) {
            return (v / 1024 / 1024 / 1024).toFixed(2) + 'GB';
        }
    }
    return v;
}